home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / c / ExtrasLib.lha / ExtrasLib / Source / Keys.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  2.4 KB  |  120 lines

  1. #include <proto/keymap.h>
  2. #include <devices/inputevent.h>
  3. #include <clib/extras_protos.h>
  4. #include <stdio.h>
  5.  
  6. LONG MapCharToIE(UBYTE C, struct InputEvent *IE);
  7.  
  8. LONG MapCharToIE(UBYTE C, struct InputEvent *IE)
  9. {
  10.   UBYTE c2;
  11.   UBYTE buffer[6],*b;
  12.  
  13.   IE->ie_Class=IECLASS_RAWKEY;
  14.   b=buffer;
  15.   c2=C;
  16.   
  17.   switch(MapANSI(&c2,1,buffer,3,0))
  18.   {
  19.     case 3:
  20.       IE->ie_Prev2DownCode=*b++;
  21.       IE->ie_Prev2DownQual=*b++;
  22.     case 2:
  23.       IE->ie_Prev2DownCode=*b++;
  24.       IE->ie_Prev2DownQual=*b++;
  25.     case 1:
  26.       IE->ie_Code      =*b++;
  27.       IE->ie_Qualifier =*b;
  28.       break;
  29.     default:
  30.       return(0);
  31.   
  32.   }
  33.   return(1);
  34.  
  35. }
  36.  
  37. /****** extras.lib/key_Unshifted ******************************************
  38. *
  39. *   NAME
  40. *       key_Unshifted -- Get unshifted character of suppied character
  41. *
  42. *   SYNOPSIS
  43. *       unshiftedchar = key_Unshifted(character)
  44. *
  45. *       ULONG key_Unshifted(char);
  46. *
  47. *   FUNCTION
  48. *       Returns the unshifted character for the supplied character.
  49. *       For example (on the USA keymap) 
  50. *         key_Unshifted('#') = '3' 
  51. *         key_Unshifted('3') = '3'
  52. *
  53. *   NOTE
  54. *       This function was previously KeyUnshifted()
  55. *
  56. *   SEE ALSO
  57. *       KeyShifted()
  58. *
  59. ******************************************************************************
  60. *
  61. */
  62.  
  63.  
  64. LONG key_Unshifted(UBYTE C)
  65. {
  66.   UBYTE buffer[2];
  67.   struct InputEvent ie={0};
  68.  
  69.   if(MapCharToIE(C,&ie))
  70.   {
  71.     ie.ie_Qualifier&=~(IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT);
  72.     MapRawKey(&ie,buffer,2,0);
  73. //    printf("key_Unshifted(%c) = %c\n",C,buffer[0]);
  74.     return(buffer[0]);
  75.   }
  76.   return(-1);
  77. }
  78.  
  79. /****** extras.lib/key_Shifted ******************************************
  80. *
  81. *   NAME
  82. *       key_Shifted -- Get shifted character of suppied character
  83. *
  84. *   SYNOPSIS
  85. *       shiftedchar = key_Shifted(character)
  86. *
  87. *       ULONG key_Shifted(char);
  88. *
  89. *   FUNCTION
  90. *       Returns the shifted character for the supplied character.
  91. *       For example (on the USA keymap) 
  92. *         key_Shifted('#') = '#' 
  93. *         key_Shifted('3') = '#'
  94. *
  95. *   NOTE
  96. *       This function was previously KeyShifted()
  97. *
  98. *   SEE ALSO
  99. *       Key_Unshifted()
  100. *
  101. ******************************************************************************
  102. *
  103. */
  104.  
  105. LONG key_Shifted(UBYTE C)
  106. {
  107.   UBYTE buffer[2];
  108.   struct InputEvent ie={0};
  109.   
  110.   if(MapCharToIE(C,&ie))
  111.   {
  112.     ie.ie_Qualifier|=(IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT);
  113.     MapRawKey(&ie,buffer,2,0);
  114. //        printf("key_Shifted(%c) = %c\n",C,buffer[0]);
  115.     return(buffer[0]);
  116.   }
  117.   return(-1);
  118. }
  119.  
  120.